attribute vec3 aVertexPosition;
attribute vec3 aVertexNorm;

uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat4 uNMatrix;

uniform vec3 uAmbLightColor;
uniform vec3 uDirLightDiffColor;
uniform vec3 uDirLightSpecColor;
uniform vec3 uDirLightVect;
uniform vec4 uMatSpecular;

varying vec3 vLightWeight;
varying vec3 vLightSpecularWeight;
varying vec4 vMatSpecular;

void main(void) {
    vec4 cameraSpacePos = uMVMatrix * vec4(aVertexPosition, 1.0);
    gl_Position = uPMatrix * cameraSpacePos;
    vec3 eyeVect = normalize(-cameraSpacePos.xyz);
    vec4 cameraSpaceNorm = uNMatrix * vec4(aVertexNorm, 0.0);
    vec3 reflectVect = reflect(uDirLightVect, cameraSpaceNorm.xyz);

    float specWeight = pow(max(dot(reflectVect, eyeVect),0.0),uMatSpecular.a);
    float diffWeight = max(dot(cameraSpaceNorm.xyz, -uDirLightVect), 0.0);
    vLightWeight = uAmbLightColor + uDirLightDiffColor * diffWeight;
    vLightSpecularWeight = uDirLightSpecColor * specWeight;
    vMatSpecular = uMatSpecular;
}

